<?php

namespace App\Modules\Task\Models;


use Illuminate\Database\Eloquent\Model;

/**
 * Class Task 任务
 * @package App\Modules\Task\Models
 */
class DrawTask extends Model
{
    protected $table = 'drawtask';

    protected $fillable = ['id','user_id','task_code','task_id', 'coin', 'created_at', 'updated_at', 'status'];


    /**
     * 领取任务
     * @param $param
     * @return mixed
     */
    static function addDrawTask($param)
    {
        // TODO check
        return self::create($param);
    }

    /**
     * 获取当日领取任务
     */
    public static function getDrawTask($task_code,$user_id){
        return self::where('task_code',$task_code)->where('user_id',$user_id)->where('created_at','>=',date('Y-m-d 00:00:00',time()))->first();
    }

    /**
     * 修改领取任务
     */
    public static function updateDrawTask($param){
        return self::where('id',$param['id'])->update($param);
    }

    /**
     * 获取当日领取任务（健康档案使用）
     */
    public static function getHealthDrawTask($task_code,$user_id){
        return self::where('task_code',$task_code)->where('user_id',$user_id)->first();
    }
}